/*
 *   Copyright (c) 2010-2022, SIUFUNG
 */
package net.siufung.market.base.app.controller.assembler;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.google.common.collect.Lists;
import net.siufung.core.utils.CopyUtil;
import net.siufung.market.base.app.controller.model.app.AppVo;
import net.siufung.market.base.app.mapper.entity.App;

import java.util.List;
import java.util.Objects;

/**
 *
 * 应用信息 持久层展示层组装器
 *
 * @author 陈建峰
 * @date 2023-01-12 16:24:13
 * @since v1.0.0
 */
public class AppAssembler {

    /**
     * App 转换成 AppVo
     * @param app 数据库实体
     * @return AppVo 视图
     */
    public static AppVo from(App app){
        if(!Objects.isNull(app)){
            AppVo appVo = new AppVo();
            CopyUtil.copyProperties(app, appVo);
            return appVo;
        }
        return null;
    }

    /**
     * AppList 转换成 AppVoList
     * @param appList 数据库实体集合
     * @return List<AppVo> 视图集合
     */
    public static List<AppVo> fromList(List<App> appList){
        List<AppVo> appVoList = Lists.newArrayList();
        if(!CollectionUtils.isEmpty(appList)){
            AppVo appVo;
            for (App app: appList) {
                appVo = new AppVo();
                CopyUtil.copyProperties(app, appVo);
                appVoList.add(appVo);
            }
        }
        return appVoList;
    }
}

